import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

class _PageNewsItem extends StatelessWidget {
  final String _title;
  final String _time;
  final int _index;
  _PageNewsItem(int index, String title, String time)
      : assert(title != null, time != null),
        _title = title,
        _index = index,
        _time = time;

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      onTap: () {
        onItemClick(_index);
      },
      child: Container(
        padding: const EdgeInsets.all(10.0),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            bottom: BorderSide(color: Color(0xffebebeb), width: 1.0),
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          //crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              width: 10.0,
            ),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    _title,
                    style: TextStyle(fontSize: 14.0, color: Color(0xff333333)),
                  ),
                ],
              ),
            ),
            SizedBox(
              width: 10.0,
            ),
            Column(
              children: <Widget>[
                Text(_time,
                    style: TextStyle(fontSize: 10.0, color: Color(0xff999999))),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

void onItemClick(int index) {
  print('点击了cell$index');
}

class ParkNews extends StatefulWidget {
  @override
  _ParkNewsState createState() => _ParkNewsState();
}

class _ParkNewsState extends State<ParkNews>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    //getHttp();

    final List data = [
      {'title': '1维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '2维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '3维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '4维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '5维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '6维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '7维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '8维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '9维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '10维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '11维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '12维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '13维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '14维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '15维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '16维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '17维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '18维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '19维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'},
      {'title': '20维扬开发区荷叶社区荷香学堂开展安全警示教育课', 'time': '12:10'}
    ];
    return new Scaffold(
      appBar: new AppBar(
        title: Text('园区动态'),
      ),
      body: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          
          index ++;
          print('在初始化$index');
          return new _PageNewsItem(index-1, data[index-1]['title'], data[index-1]['time']);
          
        },
        itemCount: data.length,
      ),
    );
  }
}

void getHttp() async {
  try {
    Response response = await Dio().get(
        "https://www-api.86links.cn/admin/park/contents?size=20&language-zh-cn&page=0&parkId=6290077928520683520");
    print(response);
  } catch (e) {
    print(e);
  }
}
